<template>
  <div class="consultation">
    <h2>文件上传下载</h2>

    <el-upload
      class="avatar-uploader"
      :action="'/upload'"
      :show-file-list="false"
      :before-upload="beforeFun"
      :on-success="handleAvatarSuccess"
    >
      <i class="el-icon-plus avatar-uploader-icon"></i>
    </el-upload>
    <el-button type="primary" size="mini" @click="download">下载</el-button>
    <div :id="luckysheetParam.containerId" class="container" />
  </div>
</template>

<script>
import LuckyExcel from "luckyexcel";
import { getRole, addRole, deleteRole, updateRole } from "../service.js";
export default {
  name: "home",
  mounted() {},
  data() {
    return {
      // excel基础配置
      luckysheetParam: {
        // 对应区域
        containerId: "editSheet",
        // 语言
        lang: "zh",
      },
    };
  },
  methods: {
    /**
     * @description: 初始化excel
     * @author: flyer
     * @param {Object} exportJson 初始化数据
     */
    initExcel(exportJson = {}) {
      // eslint-disable-next-line no-undef
      luckysheet.create({
        container: this.luckysheetParam.containerId, // luckysheet为容器id
        lang: this.luckysheetParam.lang,
        showtoolbar: true,
        showtoolbarConfig: {
          print: false, // 隐藏插件内部打印按钮
        },
        showinfobar: false, // 显示头部返回标题栏
        data: exportJson.sheets,
      });
    },
    handleAvatarSuccess(info) {
    },
    beforeFun(file) {
      luckysheet.destroy();
      LuckyExcel.transformExcelToLucky(file, (exportJson) => {
        if (exportJson.sheets == null || exportJson.sheets.length === 0) {
          this.$message.warning("读取excel文件内容失败，目前不支持xls文件!");
          return;
        }
        this.initExcel(exportJson);
      });
    },
    upload() {},
    download() {},
  },
};
</script>

<style scoped>
h2 {
  text-align: center;
  margin-top: 20px;
  margin-bottom: 20px;
}
h5 {
  color: #918787;
  margin-bottom: 30px;
}
.consultation-block {
  width: 90%;
  margin-left: 5%;
}

.pagination {
  text-align: center;
  margin-top: 20px;
}
.el-tag + .el-tag {
  margin-left: 10px;
}
.button-new-tag {
  margin-left: 10px;
  height: 32px;
  line-height: 30px;
  padding-top: 0;
  padding-bottom: 0;
}
.input-new-tag {
  width: 90px;
  margin-left: 10px;
  vertical-align: bottom;
}

.el-icon-circle-close {
  position: absolute;
  top: -5px;
  right: -5px;
  cursor: pointer;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 60px;
  height: 60px;
  line-height: 60px;
  border: 1px dashed gray;
  text-align: center;
}
.avatar {
  width: 60px;
  height: 60px;
  display: block;
}
.container {
  width: 100%;
  height: 80vh;
}
</style>
